package com.wk.springboot.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class KafkaProducer {

    private static final String TOPIC = "my_topic";

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendMessage(String message,Integer threadSize) {
        for (int i = 0; i < threadSize; i++) {
            new Thread(() -> {
                kafkaTemplate.send(TOPIC, message);
                System.out.println("Message sent: " + message);
            }).start();
        }

    }
}